package com.xinqi.modules.sys.appversion.controller.html;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.Param;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.appversion.dto.req.AppVersionHtmlQueryDTO;
import com.xinqi.modules.sys.appversion.dto.req.AppVersionLatestQueryDTO;
import com.xinqi.modules.sys.appversion.dto.rsp.AppVersionResultDTO;
import com.xinqi.modules.sys.appversion.service.AppVersionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 版本记录列表WEB控制层
 *
 * @author: linkai
 * @date: 2023/04/27
 */
@Tag(name = "app-version-html", description = "版本记录列表H5接口")
@RestController
@RequestMapping("/html/app-version")
@RequiredArgsConstructor
public class AppVersionHtmlController {

    private final AppVersionService appVersionService;

    /**
     * 查询版本列表-分页
     */
    @GetMapping("/version")
    public R<PageInfo<AppVersionResultDTO>> latestVersion(Param pageable, @Validated AppVersionHtmlQueryDTO query) {
        return R.data(appVersionService.page(pageable, query));
    }

    /**
     * 查询版本-详情
     */
    @GetMapping("/version/{id}")
    public R<AppVersionResultDTO> latestVersion(@PathVariable("id") Long id) {
        return R.data(appVersionService.findById(id));
    }

    @Operation(summary = "查询最新版本")
    @PostMapping("/version/latestVersion")
    public R<AppVersionResultDTO> latestVersion(@Validated @RequestBody AppVersionLatestQueryDTO query) {
        return R.data(appVersionService.latestVersion(query));
    }

}
